
$(function(){
	var nowDate = new Date();
	$("#beginDate").html(getMonthStartDate());
	$("#endDate").html(dateTimeFormat("yyyy-MM-dd",nowDate));

	//第一次加载
	createMainTable()

	//确定按钮
	$("button#selectorBtnOK, #confirmBtn").click(function(){
		var data = {
			accountUser: $('#accountUserInput').val(),
			accountAlias: $('#accountAliasInput').val(),
			beginDate: $('#selectorBeginDateShow').html(),
			endDate: $('#selectorEndDateShow').html()
		};
		mui.back();
		createMainTable(data);
	});

	//-----------------------------查询界面开始---------------------------------------------------
	//为开始日期和结束日期设置默认值
	// $("#selectorBeginDateShow").html(getMonthStartDate());
	// $("#selectorEndDateShow").html(dateTimeFormat("yyyy-MM-dd",nowDate));
	//日期选择器
	$(".myPicker").click(function(){
		var self = this;
		//创建普通的popPicker
		var popPicker = new mui.PopPicker();
		var popDataArray = new Array();
		//创建日期形式的Depicker
		var datePicker = new mui.DtPicker({
			type: "date",
			endDate: nowDate
		});
		switch ($(self).attr('id')){
			//开始日期选择器
			case 'selectorBeginDate':
				datePicker.setSelectedValue(getMonthStartDate());
				datePicker.show(function(items) {
					$("#selectorBeginDateShow").html(items.value);
					datePicker.dispose();
				});
				break;
			//结束日期选择器
			case 'selectorEndDate':
				datePicker.show(function(items) {
					$("#selectorEndDateShow").html(items.value);
					datePicker.dispose();
				});
				break;
			default:
				break;
		}
	});

	//清空按钮
	$("button#selectorBtnCancel").click(function(){
		$('#accountUserInput').val('');
		$('#accountAliasInput').val('');
		$('#selectorBeginDateShow').html('');
		$('#selectorEndDateShow').html('');
	});


//-----------------------------查询界面结束---------------------------------------------------
});
//-----------------------------主界面开始---------------------------------------------------

function createMainTable(params){
	params = params || {};
	$("#accountUserSpan").html(params.accountUser || '');
	$("#accountAliasSpan").html(params.accountAlias|| '');
	$("#beginDate").html(params.beginDate|| '');
	$("#endDate").html(params.endDate|| '');

	// $('.no-data').html('<span class="mui-spinner"></span>');
	//var pageNo = params.pageIndex || 0;
	$('#table').html("");
	layui.use('table', function(){
		var table = layui.table;

		//第一个实例
		table.render({
			elem: '#table'
			,limit: 10000
			// ,skin: 'line'
			,even: true
			,size: 'sm'
			,sums: true
			,height: $(window).height() - $('.head-search').height() - 60
			,url: url1 + Utils.Api.rptMgntHbzj //数据接口
			,where: {
				accessid: window.localStorage.accessid || '',
				qryDateB: params.beginDate|| '',
				qryDateE: params.endDate|| '',
				qryAccount: params.accountUser || '',
				qryAlias: params.accountAlias || ''
			}
			,response: {
				statusName: 'hasError', //数据状态的字段名称，默认：code
				statusCode: false, //成功的状态码，默认：0
				msgName: 'error', //状态信息的字段名称，默认：msg
				countName: 'results', //数据总数的字段名称，默认：count
				dataName: 'rows' //数据列表的字段名称，默认：data
			}
			,page: false //开启分页
			,cols: [[ //表头
				{field: 'accountAlias', title: '账号简称',templet: '#titleTpl',align: 'center'}
				,{field: 'amountSign', title: '账户余额', templet: '#money',align: 'center'}
			]]
			,done: function(res){
				$('#total').html(res.pageSummary.amountSign)
			}
		});

	});
}


function Detail(kcAccountId, kcMxUnitId){
	//账户资金余额明细
	var detailParams = {
		kcAccountId: kcAccountId,
		kcMxUnitId: kcMxUnitId,
		dateBeign: $('#selectorBeginDateShow').html(),
		dateEnd: $('#selectorEndDateShow').html()
	};
	mui.openWindow({
		url: 'accountBalanceDetail.html',
	})
	window.localStorage.zhParams = JSON.stringify(detailParams)
}
